﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;

namespace Windvoice.Authorize
{
    public partial class User : ActiveRecordBase<User>
    {
        public static User[] GetList(int pageIndex, int pageSize, out int recordCount)
        {
            recordCount = FindAll().Count();
            return FindAll().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToArray();
        }

        public User SaveFromConnector()
        {
            var query = from u in User.FindAll() where u.Source == this.Source && u.UniqueID == this.UniqueID select u;
            if (query.Count() != 1)
                this.Save();
            else
                this.ID = User.FindAll().Where(u => u.UniqueID == this.UniqueID && u.Source == this.Source).Single().ID;

            return this;
        }
    }
}
